const GRADES = [{ "value": "1", "name": "一年级", "CN": "一" }, 
                { "value": "2", "name": "二年级", "CN": "二" },
                { "value": "3", "name": "三年级", "CN": "三"},
                { "value": "4", "name": "四年级", "CN": "四"},
                { "value": "5", "name": "五年级", "CN": "五"},
                { "value": "6", "name": "六年级", "CN": "六"}]

/**
 * 根据序号获取年级对象
 */
function getGradeByIndex(index) {
  return GRADES[index]
}

function getGradeByEnrolDate(enrolDate) {
  if (enrolDate) {
    var date = new Date()
    var year = date.getFullYear()
    var month = date.getMonth()

    if (month < 9) {
      year = year - 1
    }

    var grade = year - enrolDate + 1

    return GRADES[grade - 1]
  }else {
    return { "value": "", "name": "", "CN": "" }
  }
}

module.exports = {
  GRADES: GRADES,
  getGradeByIndex: getGradeByIndex,
  getGradeByEnrolDate: getGradeByEnrolDate
}